/**
  ************************************* Copyright ******************************
  * FileName   : io_ctrl.c
  * Version    : v1.0
  * Author     : yychao
  * Date       : 2023-08-07
  * Description:
  * Function List:
  	1. ....
  	   <version>:
  <modify staff>:
  		  <data>:
   <description>:
  	2. ...
  ******************************************************************************
 */
#include "io_ctrl.h"
#include "gpio.h"
#include "log.h"
#include "screen.h"
#include "soft_timer.h"
#include "lfs_port.h"
#if 0
const uint8_t ctrl_table[][6]= {
    /*00*/    {	0	, 0		, 0		, 0		, 0		, 0  	},
    /*01*/    {	1	, 70	, 130	, 59	, 10	, 60	},
    /*02*/    {	1	, 65	, 135	, 61	, 11	, 56	},
    /*03*/    {	1	, 59	, 140	, 64	, 13	, 51	},
    /*04*/    {	2	, 54	, 145	, 66	, 15	, 46	},
    /*05*/    {	2	, 48	, 150	, 68	, 17	, 42	},
    /*06*/    {	3	, 42	, 155	, 70	, 19	, 37	},
    /*07*/    {	3	, 37	, 160	, 72	, 20	, 32	},
    /*08*/    {	4	, 31	, 165	, 75	, 22	, 27	},
    /*09*/    {	4	, 25	, 170	, 77	, 24	, 23	},
    /*10*/    {	5	, 20	, 180	, 81	, 26	, 18	},
    /*11*/    {	5	, 14	, 220	, 100	, 28	, 13	},
};
#else
const uint8_t ctrl_table[][6]= {
    /*00*/    {	0	, 0		, 0		, 0		, 0		, 0 },
    /*01*/    {	1	, 1		, 130	, 59	, 2		, 4	},
    /*02*/    {	1	, 1		, 135	, 61	, 2		, 4	},
    /*03*/    {	1	, 1		, 140	, 64	, 2		, 4	},
    /*04*/    {	1	, 1		, 145	, 66	, 2		, 4	},
    /*05*/    {	1	, 1		, 150	, 68	, 2		, 4	},
    /*06*/    {	1	, 1		, 155	, 70	, 2		, 4	},
    /*07*/    {	1	, 1		, 160	, 72	, 2		, 4	},
    /*08*/    {	1	, 1		, 165	, 75	, 2		, 4	},
    /*09*/    {	1	, 1		, 170	, 77	, 2		, 4	},
    /*10*/    {	1	, 1		, 180	, 81	, 2		, 4	},
    /*11*/    {	1	, 1		, 220	, 100	, 2		, 4	},

};
#endif
const float diff_table[]= {
    /*00*/ 		-0.3,
    /*01*/ 		0.0,
    /*02*/ 		0.3,
    /*03*/ 		0.6,
    /*04*/ 		0.9,
    /*05*/ 		1.2,
    /*06*/ 		1.5,
    /*07*/ 		2.0,
    /*08*/ 		2.5,
    /*09*/ 		3.0,
    /*10*/ 		4.0,
    /*11*/ 		5.0,
};
struct ctrl_state ctrl_state_st;
struct dev_sta dev_sta_ready;
struct dev_sta dev_sta_real;

void ctrl_manage(void)
{
    static uint32_t cnt = 0;
    cnt++;
    uint16_t temp = 0;
    if(ctrl_state_st.status == 1) {
        if(ctrl_state_st.time_chk == 1) {
            ctrl_state_st.past_time += (0.0167);//0.0167
            temp = ctrl_state_st.past_time * 10;
            screen_write(DIS_MAIN_PAST, (uint16_t*)&temp, 1);
            if(ctrl_state_st.past_time >= ctrl_state_st.all_time) {
				ctrl_state_st.past_time = 0;
				temp = ctrl_state_st.past_time;
				screen_write(DIS_MAIN_PAST, (uint16_t*)&temp, 1);
                ctrl_state_st.stage_item = ctrl_state_st.stage_item + 1;
                ctrl_state_st.stage = ctrl_state_st.stage_item / 2;
                if(ctrl_state_st.stage_item >=  20 ) {
                    if(dev_sta_real.fire != 0) {
                        dev_sta_ready.fire = 0;
                    }

                    if(dev_sta_real.feed != 0) {
                        dev_sta_ready.feed = 0;
                        dev_sta_real.feed = 0;
                        gpio_off(GPIOB, GPIO_PIN_12);
                        temp = PIC_OFF;
                        screen_write(P_CTRL_FEED, (uint16_t*)&temp, 1);
                    }

                    if(dev_sta_real.clear != 0) {
                        dev_sta_ready.clear = 0;
                        dev_sta_real.clear = 0;
                        gpio_off(GPIOE, GPIO_PIN_12);
                        temp = PIC_OFF;
                        screen_write(P_CTRL_CLEAR, (uint16_t*)&temp, 1);
                    }

                    if(dev_sta_real.burn_fan != 0) {
                        dev_sta_ready.burn_fan = 0;
                    }
                    if(dev_sta_real.cycle_fan != 0) {
                        dev_sta_ready.cycle_fan = 0;
                    }
                    if(dev_sta_real.air_door != 0) {
                        dev_sta_ready.air_door = 0;
                    }
                    temp = PIC_OFF;
                    screen_write(P_CTRL_BAKE, (uint16_t*)&temp, 1);
                    ctrl_state_st.stage = 0;
                    ctrl_state_st.stage_item = 0;
                    ctrl_state_st.status = 0;
                    ctrl_state_st.time_sta = 0;
                    ctrl_state_st.time_cnt = 0;
                    ctrl_state_st.past_time = 0;
                    ctrl_state_st.residual_time = ctrl_state_st.all_time;
                    temp = ctrl_state_st.stage_item + 1;
                    screen_write(DIS_MAIN_STAGE, (uint16_t*)&temp, 1);
                    temp = ctrl_state_st.past_time * 10;
                    screen_write(DIS_MAIN_PAST, (uint16_t*)&temp, 1);
                } else {
                    temp = ctrl_state_st.stage_item + 1;
                    screen_write(DIS_MAIN_STAGE, (uint16_t*)&temp, 1);
                }
                for(uint8_t i = 0; i < 20; i++) {
                    if((ctrl_state_st.stage_item % 2) == 0) {
                        ctrl_state_st.final_dry_aim = screen_curve_st.dry[ctrl_state_st.stage];
                        temp = screen_curve_st.dry[ctrl_state_st.stage];
                        screen_write(DIS_MAIN_AIM_DRY, (uint16_t*)&temp, 1);
                        ctrl_state_st.final_dry_aim /=10;
                        ctrl_state_st.all_time = screen_curve_st.up[ctrl_state_st.stage];
                        ctrl_state_st.all_time /= 10;
                        ctrl_state_st.past_time = 0;
                        //ctrl_state_st.residual_time = ctrl_state_st.all_time - ctrl_state_st.past_time;
                        ctrl_state_st.residual_time = ctrl_state_st.all_time;
                    } else {
                        ctrl_state_st.final_dry_aim = screen_curve_st.dry[ctrl_state_st.stage];
                        temp = screen_curve_st.dry[ctrl_state_st.stage];
                        screen_write(DIS_MAIN_AIM_DRY, (uint16_t*)&temp, 1);
                        ctrl_state_st.final_dry_aim /=10;
                        ctrl_state_st.all_time = screen_curve_st.std[ctrl_state_st.stage];
                        ctrl_state_st.all_time /= 10;
                        ctrl_state_st.past_time = 0;
                        //ctrl_state_st.residual_time = ctrl_state_st.all_time - ctrl_state_st.past_time;
                        ctrl_state_st.residual_time = ctrl_state_st.all_time;
                    }

                }

            }
            ctrl_state_st.time_chk = 0;
        }

        if((ctrl_state_st.stage_item % 2) == 0) {
            ctrl_state_st.residual_time = ctrl_state_st.all_time - ctrl_state_st.past_time;
            ctrl_state_st.slope_k = (ctrl_state_st.final_dry_aim - ctrl_state_st.now_dry_value) / ctrl_state_st.residual_time;
            ctrl_state_st.temp_dry_aim = ctrl_state_st.slope_k * (0.1);
            ctrl_state_st.diff_value = ctrl_state_st.temp_dry_aim;

        } else {
            ctrl_state_st.diff_value = ctrl_state_st.final_dry_aim - ctrl_state_st.now_dry_value;
        }

        if(ctrl_state_st.diff_value <= diff_table[0]) {
            ctrl_state_st.tab = 0;

        } else if(ctrl_state_st.diff_value > diff_table[11]) {
            ctrl_state_st.tab = 11;
        } else {
            for(uint8_t i = 0; i < 10; i++) {
                if((diff_table[i] < ctrl_state_st.diff_value)&&(ctrl_state_st.diff_value <= diff_table[i + 1])) {
                    ctrl_state_st.tab = i + 1;
                    break;
                }
            }
        }
        if((cnt % 10000) == 0) {
            cnt = 0;
//            LOG_DEBUG("\x1b[2J\x1b[H");
            LOG_DEBUG("\
********************************************************\r\n\
stage            &   %d \r\n\
stage_item       &   %d \r\n\
time_cnt         &   %d \r\n\
all_time         &   %f \r\n\
past_time        &   %f \r\n\
residual_time    &   %f \r\n\
final_dry_aim    &   %f \r\n\
now_dry_value    &   %f \r\n\
slope_k          &   %f \r\n\
temp_dry_aim     &   %f \r\n\
diff_value       &   %f \r\n\
--------------------------------------------------------\r\n\
Execute ctrl_table[%d]\r\n\
********************************************************\r\n\
",
                      ctrl_state_st.stage + 1,
                      ctrl_state_st.stage_item + 1,
                      ctrl_state_st.time_cnt,
                      ctrl_state_st.all_time,
                      ctrl_state_st.past_time,
                      ctrl_state_st.residual_time,
                      ctrl_state_st.final_dry_aim,
                      ctrl_state_st.now_dry_value,
                      ctrl_state_st.slope_k,
                      ctrl_state_st.temp_dry_aim,
                      ctrl_state_st.diff_value,
                      ctrl_state_st.tab);
        }
        if(ctrl_state_st.status == 1) {
            if(ctrl_state_st.tab != 0) {
                if(dev_sta_ready.feed == 1) {
                    if(ctrl_state_st.feed_cnt >= ctrl_table[ctrl_state_st.tab][0]) {
                        LOG_DEBUG("To close feed %d(s)\r\n",ctrl_table[ctrl_state_st.tab][1]);
                        dev_sta_ready.feed = 0;
                        ctrl_state_st.feed_cnt = 0;
                    }
                } else {
                    if(ctrl_state_st.feed_cnt >= ctrl_table[ctrl_state_st.tab][1]) {
                        LOG_DEBUG("To open feed %d(s)\r\n",ctrl_table[ctrl_state_st.tab][0]);
                        dev_sta_ready.feed = 1;
                        ctrl_state_st.feed_cnt = 0;
                    }
                }
            } else {
                dev_sta_ready.feed = 0;
            }
            if(ctrl_state_st.tab != 0) {
                if(dev_sta_ready.clear == 0) {
					    if(ctrl_state_st.clear_cnt >= ctrl_table[ctrl_state_st.tab][5]) {
                        LOG_DEBUG("To open clear on right %d(s)\r\n",ctrl_table[ctrl_state_st.tab][4]);
                        dev_sta_ready.clear = 1;
                        ctrl_state_st.clear_cnt = 0;
                    }					
                } else if(dev_sta_ready.clear == 1) {
				    if(ctrl_state_st.clear_cnt >= ctrl_table[ctrl_state_st.tab][4]) {
                        LOG_DEBUG("To open clear on left %d(s)\r\n",ctrl_table[ctrl_state_st.tab][4]);
                        dev_sta_ready.clear = 2;
                        ctrl_state_st.clear_cnt = 0;
                    }
                }else if(dev_sta_ready.clear == 2) {
                    if(ctrl_state_st.clear_cnt >= ctrl_table[ctrl_state_st.tab][4]) {
                        LOG_DEBUG("To close clear %d(s)\r\n",ctrl_table[ctrl_state_st.tab][5]);
                        dev_sta_ready.clear = 0;
                        ctrl_state_st.clear_cnt = 0;
                    }
				}
#if 0
				
				if(dev_sta_ready.clear == 0) {
				    if(ctrl_state_st.clear_cnt >= ctrl_table[ctrl_state_st.tab][5]) {
                        LOG_DEBUG("To open clear %d(s)\r\n",ctrl_table[ctrl_state_st.tab][4]);
                        dev_sta_ready.clear = 1;
                        ctrl_state_st.clear_cnt = 0;
                    }
                } else if(dev_sta_ready.clear == 1) {
                    if(ctrl_state_st.clear_cnt >= ctrl_table[ctrl_state_st.tab][4]) {
                        LOG_DEBUG("To close clear %d(s)\r\n",ctrl_table[ctrl_state_st.tab][5]);
                        dev_sta_ready.clear = 0;
                        ctrl_state_st.clear_cnt = 0;
                    }
                }
				
				
#endif
            } else {
                dev_sta_ready.clear = 0;
            }

        }


        if(ctrl_state_st.tab != 0) {
            if(dev_sta_real.burn_fan == 0) {
                LOG_DEBUG("Ready Open burn_fan\r\n");
                dev_sta_ready.burn_fan = 1;
            }
        } else {
            if(dev_sta_real.burn_fan == 1) {
                LOG_DEBUG("Ready Close burn_fan\r\n");
                dev_sta_ready.burn_fan = 0;
            }
        }


        if(dev_sta_real.cycle_fan == 0) {
            LOG_DEBUG("Ready Open cycle_fan\r\n");
            dev_sta_ready.cycle_fan = 1;
        }
#if 1
        if(dev_sta_real.air_door == 0) {
            LOG_DEBUG("Ready Open air_door\r\n");
            dev_sta_ready.air_door = 1;
        }
#endif
    }

    if(dev_sta_ready.fire != dev_sta_real.fire) {
        if(dev_sta_ready.fire == 0) {
            LOG_DEBUG("Close fire\r\n");
            gpio_off(GPIOE, GPIO_PIN_14);
            temp = PIC_OFF;
            screen_write(P_CTRL_FIRE, (uint16_t*)&temp, 1);
        } else {
            LOG_DEBUG("Open fire\r\n");
            gpio_on(GPIOE, GPIO_PIN_14);
            temp = PIC_ON;
            screen_write(P_CTRL_FIRE, (uint16_t*)&temp, 1);
        }
        dev_sta_real.fire = dev_sta_ready.fire;
    }

    if(dev_sta_ready.feed != dev_sta_real.feed) {
        if(dev_sta_ready.feed == 0) {
            LOG_DEBUG("Close feed\r\n");
            gpio_off(GPIOB, GPIO_PIN_12);
            temp = PIC_OFF;
            screen_write(P_CTRL_FEED, (uint16_t*)&temp, 1);
        } else if(dev_sta_ready.feed == 1) {
            gpio_on(GPIOB, GPIO_PIN_12);
            temp = PIC_ON;
            screen_write(P_CTRL_FEED, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open feed\r\n");
        }
        dev_sta_real.feed = dev_sta_ready.feed;
    }

    if(dev_sta_ready.clear != dev_sta_real.clear) {
        if(dev_sta_ready.clear == 0) {
			LOG_DEBUG("Close clear\r\n");
            gpio_off(GPIOE, GPIO_PIN_12);
			gpio_off(GPIOC, GPIO_PIN_7);
            temp = PIC_OFF;
            screen_write(P_CTRL_CLEAR, (uint16_t*)&temp, 1);
        } else if(dev_sta_ready.clear == 1) {
            gpio_on(GPIOE, GPIO_PIN_12);
            gpio_on(GPIOE, GPIO_PIN_11);
			
			gpio_on(GPIOC, GPIO_PIN_7);
			gpio_on(GPIOC, GPIO_PIN_6);
            temp = PIC_ON;
            screen_write(P_CTRL_CLEAR, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open clear right\r\n");
        }else if(dev_sta_ready.clear == 2){
            gpio_on(GPIOE, GPIO_PIN_12);
            gpio_off(GPIOE, GPIO_PIN_11);
			
			gpio_on(GPIOC, GPIO_PIN_7);
			gpio_off(GPIOC, GPIO_PIN_6);
            temp = PIC_ON;
            screen_write(P_CTRL_CLEAR, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open clear left\r\n");
		}
#if 0
		if(dev_sta_ready.clear == 0) {
			LOG_DEBUG("Close clear\r\n");
            gpio_off(GPIOE, GPIO_PIN_12);
            temp = PIC_OFF;
            screen_write(P_CTRL_CLEAR, (uint16_t*)&temp, 1);
        } else if(dev_sta_ready.clear == 1) {
            gpio_on(GPIOE, GPIO_PIN_12);
            gpio_on(GPIOE, GPIO_PIN_11);
            temp = PIC_ON;
            screen_write(P_CTRL_CLEAR, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open clear right\r\n");
        }
#endif
        dev_sta_real.clear = dev_sta_ready.clear;
    }


    if(dev_sta_ready.burn_fan != dev_sta_real.burn_fan) {
        if(dev_sta_ready.burn_fan == 0) {
            LOG_DEBUG("Close burn_fan\r\n");
            temp = PIC_OFF;
            screen_write(P_CTRL_BFAN, (uint16_t*)&temp, 1);
        } else if(dev_sta_ready.burn_fan == 1) {
            temp = PIC_ON;
            screen_write(P_CTRL_BFAN, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open burn_fan\r\n");
        }
        dev_sta_real.burn_fan = dev_sta_ready.burn_fan;
    }

    if(dev_sta_real.burn_fan  == 1) {
        if(ctrl_state_st.status == 1) {
            dev_sta_ready.duty_ratio = ctrl_table[ctrl_state_st.tab][3];
        } else {
            dev_sta_ready.duty_ratio_f = bake_ctrl[0];
            dev_sta_ready.duty_ratio_f /= 220;
            dev_sta_ready.duty_ratio = dev_sta_ready.duty_ratio_f * 100;
        }

    } else {
        dev_sta_ready.duty_ratio = 0;
    }
    if(dev_sta_ready.duty_ratio != dev_sta_real.duty_ratio) {
        dev_sta_real.duty_ratio = dev_sta_ready.duty_ratio;
        LOG_DEBUG("Burn_fan duty_ratio %d\r\n", dev_sta_real.duty_ratio);
    }

    if(dev_sta_ready.cycle_fan != dev_sta_real.cycle_fan) {
        if(dev_sta_ready.cycle_fan == 0) {
            LOG_DEBUG("Close cycle_fan\r\n");
            temp = PIC_OFF;
            screen_write(P_CTRL_CYCLE, (uint16_t*)&temp, 1);
        } else if(dev_sta_ready.cycle_fan == 1) {
            temp = PIC_ON;
            screen_write(P_CTRL_CYCLE, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open cycle_fan\r\n");
        }
        dev_sta_real.cycle_fan = dev_sta_ready.cycle_fan;
    }

    if(dev_sta_real.cycle_fan  == 1) {
        if(ctrl_state_st.status == 1) {
            if(ctrl_state_st.tab <= 4 ) {
                dev_sta_ready.cycle_level = 1;
            } else {
                dev_sta_ready.cycle_level = 2;
            }
        } else {
            dev_sta_ready.cycle_level = bake_ctrl[1];
        }
    } else {
        dev_sta_ready.cycle_level = 0;
    }
    if(dev_sta_ready.cycle_level != dev_sta_real.cycle_level) {
        dev_sta_real.cycle_level = dev_sta_ready.cycle_level;
        LOG_DEBUG("cycle_level %d\r\n", dev_sta_real.cycle_level);
        switch(dev_sta_real.cycle_level) {
        case 0:
            gpio_off(GPIOB, GPIO_PIN_14);
            break;
        case 1:
            gpio_on(GPIOB, GPIO_PIN_14);
            gpio_on(GPIOB, GPIO_PIN_13);
            break;
        case 2:
		    gpio_on(GPIOB, GPIO_PIN_14);
            gpio_off(GPIOB, GPIO_PIN_13);
            break;
        default:
            gpio_off(GPIOB, GPIO_PIN_14);
            break;
        }
    }


    if(dev_sta_ready.air_door != dev_sta_real.air_door) {
        if(dev_sta_ready.air_door == 0) {
            LOG_DEBUG("Close air_door\r\n");
            temp = PIC_OFF;
            screen_write(P_CTRL_AIR, (uint16_t*)&temp, 1);
        } else if(dev_sta_ready.air_door == 1) {
            temp = PIC_ON;
            screen_write(P_CTRL_AIR, (uint16_t*)&temp, 1);
            LOG_DEBUG("Open air_door\r\n");
        }
        dev_sta_real.air_door = dev_sta_ready.air_door;
    }

    if(dev_sta_real.air_door  == 1) {

        if(ctrl_state_st.status == 1) {
            dev_sta_ready.air_level = 1;
        } else {
            dev_sta_ready.air_level = bake_ctrl[2];
        }
    } else {
        dev_sta_ready.air_level = 0;
    }
    if(dev_sta_ready.air_level != dev_sta_real.air_level) {
        dev_sta_real.air_level = dev_sta_ready.air_level;
        LOG_DEBUG("air_door %d\r\n", dev_sta_real.air_level);
    }
	switch(dev_sta_real.air_level) {
        case 0:
			if(1 != GPIO_ReadInputDataBit(GPIOD, GPIO_PIN_12)) {
				gpio_on(GPIOD, GPIO_PIN_8);
				gpio_off(GPIOB, GPIO_PIN_15);
			}else {
			    gpio_off(GPIOD, GPIO_PIN_8);
				gpio_off(GPIOB, GPIO_PIN_15);
			}
            break;
        case 1:
		case 2:
			if(1 != GPIO_ReadInputDataBit(GPIOD, GPIO_PIN_13)) {
				gpio_off(GPIOD, GPIO_PIN_8);
				gpio_on(GPIOB, GPIO_PIN_15);
			}else {
				gpio_off(GPIOD, GPIO_PIN_8);
				gpio_off(GPIOB, GPIO_PIN_15);
			}
            break;
        default:
            	gpio_off(GPIOD, GPIO_PIN_8);
				gpio_off(GPIOB, GPIO_PIN_15);
            break;
   }
}

void io_ctrl_init(void)
{
    /*output push leaf ctrl io_1*/
    gpio_init_out(GPIOA, GPIO_PIN_12);
    gpio_off(GPIOA, GPIO_PIN_12);
    /*output push leaf ctrl io_2*/
    gpio_init_out(GPIOA, GPIO_PIN_11);
    gpio_off(GPIOA, GPIO_PIN_11);

    /*output camera power*/
    gpio_init_out(GPIOA, GPIO_PIN_8);
    gpio_off(GPIOA, GPIO_PIN_8);

    /*output camera lamp*/
    gpio_init_out(GPIOC, GPIO_PIN_9);
    gpio_off(GPIOC, GPIO_PIN_9);

    /*output bk1*/
    gpio_init_out(GPIOC, GPIO_PIN_8);
    gpio_off(GPIOC, GPIO_PIN_8);

    /*output PUSH_ROD_VCC*/
    gpio_init_out(GPIOC, GPIO_PIN_7);
    gpio_off(GPIOC, GPIO_PIN_7);
    /*output PUSH_ROD TURN Forward/Backward*/
    gpio_init_out(GPIOC, GPIO_PIN_6);
    gpio_off(GPIOC, GPIO_PIN_6);

    /*input bk1*/
    gpio_init_in(GPIOD, GPIO_PIN_15);
    /*input bk2*/
    gpio_init_in(GPIOD, GPIO_PIN_14);


    /*input I_AIR_DOOR_ON*/
    gpio_init_in(GPIOD, GPIO_PIN_13);
    /*input I_AIR_DOOR_OFF*/
    gpio_init_in(GPIOD, GPIO_PIN_12);

    /*output AIR_DOOR ctrl io_1*/
    gpio_init_out(GPIOD, GPIO_PIN_8);
    gpio_off(GPIOD, GPIO_PIN_8);
    /*output AIR_DOOR ctrl io_2*/
    gpio_init_out(GPIOB, GPIO_PIN_15);
    gpio_off(GPIOB, GPIO_PIN_15);


    /*output CYCLE_FAN CTRL*/
    gpio_init_out(GPIOB, GPIO_PIN_14);
    gpio_off(GPIOB, GPIO_PIN_14);
    /*output CYCLE_FAN High/Low Speed*/
    gpio_init_out(GPIOB, GPIO_PIN_13);
    gpio_off(GPIOB, GPIO_PIN_13);

    /*output FEED_MOTOR CTRL*/
    gpio_init_out(GPIOB, GPIO_PIN_12);
    gpio_off(GPIOB, GPIO_PIN_12);

    /*output BURNER_ROD CTRL*/
    gpio_init_out(GPIOE, GPIO_PIN_14);
    gpio_off(GPIOE, GPIO_PIN_14);

    /*output BURNER_FAN CTRL*/
    gpio_init_out(GPIOE, GPIO_PIN_13);
    gpio_off(GPIOE, GPIO_PIN_13);


    /*output CLEAR_MOTOR CTRL*/
    gpio_init_out(GPIOE, GPIO_PIN_12);
    gpio_off(GPIOE, GPIO_PIN_12);
    /*output CLEAR_MOTOR Forward/Backward*/
    gpio_init_out(GPIOE, GPIO_PIN_11);
    gpio_off(GPIOE, GPIO_PIN_11);
}